package com.qianyitian.hope2.analyzer.controller;

import com.qianyitian.hope2.analyzer.config.TokenService;
import com.qianyitian.hope2.analyzer.service.RPSService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class RPSScoreController {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    RPSService rpsService;

    @GetMapping(value = "/rps/stocks/{type}")
    public String loadStockRPS(@PathVariable String type) {
        if (type.equals("aggressive")) {
            return rpsService.getAllStockRPSAggressive();
        } else {
            return rpsService.getAllStockRPSStable();
        }
    }

    @GetMapping(value = "/rps/funds/{type}")
    @CrossOrigin
    public String loadFundsRPSByType(@PathVariable String type) {
        if (type.equals("aggressive")) {
            return rpsService.getAllFundRPSAggressive();
        } else {
            return rpsService.getAllFundRPSSTable();
        }

    }

    @GetMapping(value = "/rps/refresh")
    @Scheduled(cron = "0 29 21 * * MON,TUE,WED,THU,FRI")
    public String refreshRPS() {
        int stock = 0;
        stock = rpsService.refreshStockRPS();
        int fund = rpsService.refreshFundRPS();
        return "stock:" + stock + "      fund:" + fund;
    }

    @GetMapping(value = "/rps/fund/{code}")
    public String loadFundRPS(@PathVariable String code) {
        return rpsService.getFundRPS(code);
    }

}
